package com.linkallcloud.core.dto;

import java.util.List;

public class CompareNameValue extends NameValue {
    private static final long serialVersionUID = 233355143783992982L;

    private String newVal;
    private String type;// com.linkallcloud.core.enums.FieldType: text,textarea,select,date,datetime
    private String options;// 附加信息，比如用于存储type=select时候的oprions信息key:value

    public CompareNameValue() {
        super();
        this.type = "text";
    }

    public CompareNameValue(String key, String value, String title, String type, String options) {
        this(key, value, title, type);
        this.options = options;
    }

    public CompareNameValue(String key, String value, String title, String type) {
        super(key, value, title);
        this.type = type;
    }

    public CompareNameValue(String key, String value, String title) {
        super(key, value, title);
        this.type = "text";
    }

    public CompareNameValue(String key, String value) {
        super(key, value);
        this.type = "text";
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getNewVal() {
        return newVal;
    }

    public void setNewVal(String newVal) {
        this.newVal = newVal;
    }

    public String getOptions() {
        return options;
    }

    public void setOptions(String options) {
        this.options = options;
    }

    public static List<CompareNameValue> merge(List<CompareNameValue> oldFields, List<CompareNameValue> newFields) {
        if (oldFields != null && !oldFields.isEmpty() && newFields != null && !newFields.isEmpty()
                && newFields.size() == oldFields.size()) {
            for (int i = 0; i < oldFields.size(); i++) {
                CompareNameValue cnv = oldFields.get(i);
                cnv.setNewVal(newFields.get(i).getValue());
            }
        }
        return oldFields;
    }

}
